//
//  UnsubscribeConfirmView.m
//  TimeBoat
//
//  Created by yangxiujiang on 2022/7/30.
//  Copyright © 2022 yang. All rights reserved.
//

#import "UnsubscribeConfirmView.h"
#import "BaseWebViewViewController.h"

@interface UnsubscribeConfirmView ()
///放弃注销btn
@property (weak, nonatomic) IBOutlet UIButton *cancelCancellation;
///确定注销btn
@property (weak, nonatomic) IBOutlet UIButton *confirmCancellation;
@property (weak, nonatomic) IBOutlet UIButton *selectBtn;


@end

@implementation UnsubscribeConfirmView


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self = [[NSBundle mainBundle] loadNibNamed:@"UnsubscribeConfirmView" owner:nil options:nil].lastObject;
        self.frame = frame;
        [self setSubView];
    }
    return self;
}


- (void)setSubView{
    self.confirmCancellation.enabled = NO;
    [self.confirmCancellation setBackgroundColor:[UIColor colorWithRed:237/255.0 green:112/255.0 blue:45/255.0 alpha:0.4]];
    [self.cancelCancellation setBackgroundColor:[UIColor colorWithRed:237/255.0 green:112/255.0 blue:45/255.0 alpha:1]];
}


- (IBAction)selectBtnClick:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (sender.selected) {
        self.confirmCancellation.enabled = YES;
        [self.confirmCancellation setBackgroundColor:[UIColor colorWithRed:237/255.0 green:112/255.0 blue:45/255.0 alpha:1]];
    }
    else{
        self.confirmCancellation.enabled = NO;
        [self.confirmCancellation setBackgroundColor:[UIColor colorWithRed:237/255.0 green:112/255.0 blue:45/255.0 alpha:0.4]];
    }
}


- (IBAction)cancellationAgreementClick:(UIButton *)sender {
    BaseWebViewViewController *tempVC = [BaseWebViewViewController new];
    tempVC.titleStr = @"注销协议";
    [tempVC initWebViewWithURLStr:cancellationAgreement];
    [CURRENTVC.navigationController pushViewController:tempVC animated:YES];
}


//取消注销
- (IBAction)cancelCancellationClick:(UIButton *)sender {
    [CURRENTVC.navigationController popToRootViewControllerAnimated:YES];
}


//确定注销
- (IBAction)confirmCancellationClick:(UIButton *)sender {
    NSString *token = [AccountManager shareAccount].loginModel.token;
    [[HttpHelp shareInstance] POSTHTTPV2:API_USER_unsubscribe parameters:@{@"token":token} success:^(NSDictionary * _Nonnull dict) {
        NSInteger result = [dict[@"result"] integerValue];
        if (result == 1) {
            [[AccountManager shareAccount] logout];
//            [APPDELEGATE setupLoginVC];
            [CURRENTVC.navigationController popToRootViewControllerAnimated:YES];
        }
        else{
            [GJProgressHUD mbShow:dict[@"msg"]];
        }
    } failure:^(BOOL netErr, NSString * _Nonnull error) {
        
    }];
}


@end
